﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WHC.Hotel.Entity;
using WHC.Hotel.BLL;
using WHC.Hotel.UI.Controls;
using Hotel.Service;

namespace WHC.Hotel.UI
{
    public partial class FrmRoomStatusView :BaseForm
    {    

     
        private RoomInfo selectedRoomInfo = null;
        private TableLayoutPanel roomPanel = new TableLayoutPanel();
        private Panel lastSelectPanel = null;
        private int iCol = 8;//显示几列
        private Color DirtyRoomColor = Color.DarkGray;//脏房的背景色
        private Color CleanRoomColor = Color.Green;//干净房的背景颜色
        private Color ActiveRoomColor = Color.Red;//当前活动的房间边框颜色
        private Color NormalRoomColor = SystemColors.ControlDark;//正常时候边框颜色

        private string condition = "  1=1 ";
        private string selectRoomType = "";
        private string selectRoomBuildNum = "";
        private string selectRoomFloor = "";
        private string selectRoomStatus = "";
        private bool isShowClockRoomOnly = false;

        private FrmRoomDetail mFrmRoomDetail = new FrmRoomDetail();
        public FrmRoomStatusView()
        {
            InitializeComponent();
            mFrmRoomDetail.Hide();

            lbCleanRoomColor.BackColor = CleanRoomColor;
            lbDirtyRoomColor.BackColor = DirtyRoomColor;
            Rectangle rect = new Rectangle();
            rect = Screen.GetWorkingArea(this);
            if (rect.Width <= 1024)
            {
                gbRoomView.Width = 700;
                gbRoomIcon.Width =700;
                pnRoomView.Width =680;
                iCol = 7;

            }
            else if (rect.Width < 1440)
            {

                gbRoomView.Width = 940;
                gbRoomIcon.Width = 940;
                pnRoomView.Width = 920;
                iCol = 10;
            
            }
            else
            {

                gbRoomView.Width =1100;
                gbRoomIcon.Width = 1100;
                pnRoomView.Width = 1080;
                iCol = 11;
            }
         
            ControlRoomSumViewStyle();
            CreateRoomView();
        }

        private void FrmRoomStatusView_Load(object sender, EventArgs e)
        {


            cboxRoomStatus.Text = "全部";
            ControlRoomSumViewStyle();
            CreateRoomSumView();
            //dgViewRoomType.Rows[0].Selected = false;
            //dgViewRoomArea.Rows[0].Selected = false;
            //dgViewRoomFloor.Rows[0].Selected = false;
            
        }

        /// <summary>
        /// 获取房源信息
        /// </summary>
        private void GetRoomInfo()
        {

            List<RoomInfo> mRoomInfo = BLLFactory<WHC.Hotel.BLL.Room>.Instance.FindAllRooms(condition);

        
        }
      

       
        /// <summary>
        /// 设置每个房间显示方式
        /// </summary>
        /// <param name="roomInfo"></param>
        /// <param name="mRoomStatusView"></param>
        private void SetRoomViewStatus(RoomInfo roomInfo,RoomStatusView mRoomStatusView)
        {


            switch (roomInfo.Status)
            {
                case Entity.RoomStatus.空净房:
                    mRoomStatusView.roomPanel.BackColor = CleanRoomColor;
                    mRoomStatusView.picStatus.Visible = false;
                    break;
                case Entity.RoomStatus.空脏房:
                    mRoomStatusView.roomPanel.BackColor = DirtyRoomColor;
                   // mRoomStatusView.picStatus.Image = global::WHC.Hotel.UI.Properties.Resources.trash;
                    mRoomStatusView.picStatus.Visible = false;
                    break;
                case Entity.RoomStatus.住净房:
                    mRoomStatusView.roomPanel.BackColor = CleanRoomColor;
                    if (roomInfo.OrderInfo.CheckType == 1)
                    {
                        //判断是否是团体
                        mRoomStatusView.picStatus.Image = global::WHC.Hotel.UI.Properties.Resources.team32;
                    }
                    else
                    {
                        mRoomStatusView.picStatus.Image = global::WHC.Hotel.UI.Properties.Resources.Single32;
                    
                    }
                    mRoomStatusView.picStatus.Visible = true;
                    break;
                case Entity.RoomStatus.住脏房:
                    mRoomStatusView.roomPanel.BackColor = DirtyRoomColor;
                    if (roomInfo.OrderInfo.CheckType == 1)
                    {
                        //判断是否是团体
                        mRoomStatusView.picStatus.Image = global::WHC.Hotel.UI.Properties.Resources.team32;
                    }
                    else
                    {
                        mRoomStatusView.picStatus.Image = global::WHC.Hotel.UI.Properties.Resources.Single32;

                    }
                    mRoomStatusView.picStatus.Visible = true;
                    break;
                case Entity.RoomStatus.维修房:
                    mRoomStatusView.picStatus.Image = global::WHC.Hotel.UI.Properties.Resources.maintain32;
                    mRoomStatusView.picStatus.Visible = true;
                    break;
                case Entity.RoomStatus.预定房:
                    //mRoomStatusView.picStatus.Image = global::WHC.Hotel.UI.Properties.Resources.Flag;
                    mRoomStatusView.picStatus.Visible = false;
                    break;
                case Entity.RoomStatus.锁房:
                    mRoomStatusView.picStatus.Image = global::WHC.Hotel.UI.Properties.Resources.lock32;
                    mRoomStatusView.picStatus.Visible = true;
                    break;
                case Entity.RoomStatus.强制锁房:
                    mRoomStatusView.picStatus.Image = global::WHC.Hotel.UI.Properties.Resources.forelock32;
                    mRoomStatusView.picStatus.Visible = true;
                    break;
                case Entity.RoomStatus.钟点房:
                    mRoomStatusView.picStatus.Image = global::WHC.Hotel.UI.Properties.Resources.clock32;
                    mRoomStatusView.picStatus.Visible = true;
                    break;
            }
        
        
        
        }

        private void ControlRoomSumViewStyle()
        {

            dgViewRoomType.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgViewRoomType.MultiSelect = false;
            dgViewRoomType.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            //设置引导头部文字
            dgViewRoomType.TopLeftHeaderCell.Value = "全部";
            dgViewRoomType.AutoGenerateColumns = false;

            dgViewRoomArea.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgViewRoomArea.MultiSelect = false;
            dgViewRoomArea.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            //设置引导头部文字
            dgViewRoomArea.TopLeftHeaderCell.Value = "全部";
            dgViewRoomArea.AutoGenerateColumns = false;

            dgViewRoomFloor.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgViewRoomFloor.MultiSelect = false;
            dgViewRoomFloor.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            //设置引导头部文字
            dgViewRoomFloor.TopLeftHeaderCell.Value = "全部";
            dgViewRoomFloor.AutoGenerateColumns = false;
            
        
        
        }

        /// <summary>
        /// 创建房类导航器
        /// </summary>
        private void CreateRoomSumView()
        {


            List<RoomInfo> roomList = BLLFactory<WHC.Hotel.BLL.Room>.Instance.FindAllRooms("  1=1 ");
            int inUse = 0;
            int canUse = 0;
            foreach (RoomInfo entity in roomList)
            {   
                inUse=0;
                canUse = 0;
                switch (entity.Status)
                {
                    case Entity.RoomStatus.空净房:
                        canUse = 1;
                        VCNum.Text =( Convert.ToInt32(VCNum.Text) + 1).ToString();
                        break;
                    case Entity.RoomStatus.空脏房:
                        VDNum.Text = (Convert.ToInt32(VDNum.Text) + 1).ToString();
                        canUse =1;
                        break;
                    case Entity.RoomStatus.住净房:
                        if (!entity.IsClockRoom)
                        {
                            OCNum.Text = (Convert.ToInt32(OCNum.Text) + 1).ToString();
                        }
                        else
                        {
                            ZDNum.Text = (Convert.ToInt32(ZDNum.Text) + 1).ToString();
                        
                        }
                        inUse=1;
                        break;
                    case Entity.RoomStatus.住脏房:
                        if (!entity.IsClockRoom)
                        {
                            ODNum.Text = (Convert.ToInt32(ODNum.Text) + 1).ToString();
                        }
                        else
                        {
                            ZDNum.Text = (Convert.ToInt32(ZDNum.Text) + 1).ToString();
                         
                        }
                        inUse = 1;
                        break;
                    case Entity.RoomStatus.维修房:
                        OONum.Text = (Convert.ToInt32(OONum.Text) + 1).ToString();
                        inUse = 0;
                        break;
                    case Entity.RoomStatus.预定房:
                        YDNum.Text = (Convert.ToInt32(YDNum.Text) + 1).ToString();
                        inUse = 1;
                        break;
                    case Entity.RoomStatus.锁房:
                        inUse = 0;
                        break;
                    case Entity.RoomStatus.强制锁房:
                        inUse = 0;
                        break;
                    case Entity.RoomStatus.钟点房:
                        inUse = 1;
                        break;
                }
                if (entity.OrderInfo != null && entity.OrderInfo.CreateDate.AddDays(entity.OrderInfo.PreLivedDays).ToShortDateString() == DateTime.Now.ToShortDateString())
                {

                    YLNUM.Text = (Convert.ToInt32(YLNUM.Text) + 1).ToString();
                
                }
                RoomSumList.AddRoomTypeItem(entity.RoomTypeCode+"("+entity.RoomType+")", inUse, canUse,entity.RoomType);
                RoomSumList.AddRoomBuildItem(entity.BuildNum, inUse, canUse);
                RoomSumList.AddRoomFloorItem(entity.Floor, inUse, canUse);

               

            }

            dgViewRoomType.DataSource = RoomSumList.RoomTypeSumList;
            dgViewRoomArea.DataSource = RoomSumList.RoomBuildSumList;
            dgViewRoomFloor.DataSource = RoomSumList.RoomFloorSumList;
           // dgViewRoomFloor.Sort(dgViewRoomFloor.Columns["Key"], ListSortDirection.Ascending);



        
        
        
        }

        /// <summary>
        /// 创建房态图
        /// </summary>
        private void CreateRoomView()
        {
          
            pnRoomView.Controls.Clear();
            List<RoomInfo> mRoomInfo = BLLFactory<WHC.Hotel.BLL.Room>.Instance.FindAllRooms(condition);
            if (isShowClockRoomOnly)
            {
                mRoomInfo = mRoomInfo.FindAll(delegate(RoomInfo m) { return m.IsClockRoom == true; });
            
            }
            
            int num =mRoomInfo.Count;
            int iCellWidth = 98;
            int iCellHeight = 80;
            int iCellPading = 1;
          
            roomPanel.Controls.Clear();
            int iRow = num % iCol == 0 ? num / iCol : num / iCol + 1;
            roomPanel.ColumnCount = iCol;
            roomPanel.RowCount = iRow;
            roomPanel.CellBorderStyle = TableLayoutPanelCellBorderStyle.None;
            roomPanel.Width = iCol * iCellWidth + iCol * 2;
            roomPanel.Height = iRow * iCellHeight + iRow * 2;
            int iCurrentRow = 0;
            int iCurrentCol = 0;
            int iPosition = 1;
            foreach (RoomInfo entity in mRoomInfo)
            {
          
                RoomStatusView mRoomStatusView = new RoomStatusView(); 
                mRoomStatusView.roomPanel.BackColor = CleanRoomColor;
                mRoomStatusView.BackColor = NormalRoomColor;
                mRoomStatusView.TabIndex = iPosition;
                mRoomStatusView.Margin = new Padding(iCellPading);
                mRoomStatusView.RoomNum.Text = entity.RoomNo;
                mRoomStatusView.roomPanel.Tag = entity;
                //设置房态图标
                SetRoomViewStatus(entity, mRoomStatusView);
                //设置是否预抵和预离
                if (entity.IsExistBook)
                {
                    mRoomStatusView.picArrive.Visible = (entity.BookBeginTime.Date == DateTime.Now.Date ? true : false);

                }

                mRoomStatusView.pivleft.Visible= entity.IsTodayLeave;

                //设置是否余额不足
                if (entity.OrderInfo != null)
                {
                    mRoomStatusView.picAlert.Visible = entity.OrderInfo.DepositMoney<=entity.ConsumedSum;
                }


 

                //绑定事件
                mRoomStatusView.RoomStatusViewMouseClickEvent += new RoomStatusView.RoomStatusViewMouseClickHandler(mRoomStatusView_RoomStatusViewMouseClickEvent);
                mRoomStatusView.RoomStatusViewDoubleClickEvent += new RoomStatusView.RoomStatusViewDoubleClickHandler(mRoomStatusView_RoomStatusViewDoubleClickEvent);
                mRoomStatusView.RoomStatusViewMouseHoverEvent += new RoomStatusView.RoomStatusViewMouseHoverHandler(mRoomStatusView_RoomStatusViewMouseHoverEvent);
                mRoomStatusView.RoomStatusViewMouseLeaveEvent += new RoomStatusView.RoomStatusViewMouseLeaveHandler(mRoomStatusView_RoomStatusViewMouseLeaveEvent);


                roomPanel.Controls.Add(mRoomStatusView, iCurrentCol, iCurrentRow);



                iCurrentCol++;

                if (iCurrentCol % iCol == 0)
                {
                    iCurrentCol = 0;
                    iCurrentRow++;
                }




            }
            
            roomPanel.TabIndex = 13;
            pnRoomView.Controls.Add(roomPanel);
            pnRoomView.HorizontalScroll.Visible = false;



        }

        void mRoomStatusView_RoomStatusViewMouseLeaveEvent(Panel sender, EventArgs e)
        {
            mFrmRoomDetail.Hide();
        }

        void mRoomStatusView_RoomStatusViewMouseHoverEvent(Panel sender, EventArgs e)
        {
            mFrmRoomDetail.ShowSelectedRoomInfo((RoomInfo)sender.Tag);
            mFrmRoomDetail.Location = new Point(Control.MousePosition.X + 4, Control.MousePosition.Y + 4);
            mFrmRoomDetail.Show();
        }

        /// <summary>
        /// 实际房态，查看详细信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mRoomStatusView_RoomStatusViewDoubleClickEvent(Panel sender, EventArgs e)
        {
            RoomInfo mRoomInfo= (RoomInfo)sender.Tag;
            if (mRoomInfo!= null)
            {

                if (mRoomInfo.Status == RoomStatus.空净房 || mRoomInfo.Status == RoomStatus.空脏房)
                {

                    FrmEditRoomOrder dlg = new FrmEditRoomOrder();
                    dlg.RoomInfo = mRoomInfo;
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {

                        ReflashRoomView();

                    }



                }
                else if (mRoomInfo.OrderInfo != null)
                { 
                
                  //显示详细
                
                }
            
            }


        }

        /// <summary>
        /// 右键操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private  void mRoomStatusView_RoomStatusViewMouseClickEvent(Panel sender, MouseEventArgs e)
        {


           

            if (sender != null)
            {
               // sender.BorderStyle = BorderStyle.Fixed3D;
                sender.Parent.BackColor = ActiveRoomColor;
                selectedRoomInfo = sender.Tag as RoomInfo;
                if (selectedRoomInfo == null) return;

            }

            if (lastSelectPanel != null)
            {

               // lastSelectPanel.BorderStyle = BorderStyle.None;
                lastSelectPanel.Parent.BackColor = NormalRoomColor;

            }
            lastSelectPanel = sender;
            if (e.Button.ToString() == "Right")
            {

                ControlRightMenu(sender, e);


            }
        }

     

       
        #region 右键菜单

     

        private void ControlRightMenu( Panel selectedPanel,MouseEventArgs e)
        {


               ShowRoomInfo();
           
               #region 根据不同的房态分配菜单
                if (selectedRoomInfo.Status == Entity.RoomStatus.空净房 || selectedRoomInfo.Status == Entity.RoomStatus.空脏房 || selectedRoomInfo.Status == Entity.RoomStatus.预定房)
                {
                    EnableAllContextMenu(false);
                    selectedPanel.ContextMenuStrip = this.contextMenuStrip1;
                    this.menu_ChangeStatus.Visible = false;
                    //if (selectedRoomInfo.Status != Entity.RoomStatus.空净房)
                    //{
                       this.menu_SankeBill.Enabled = true;
                       this.menu_GroupBill.Enabled = true;

                    //}
                    this.menu_BookIn.Enabled = true;
                    this.menu_SetMaintain.Enabled = true;
                    this.SetCleanRoom.Enabled = true;
                    this.SetDirtyRoom.Enabled = true;

                }
                else if (selectedRoomInfo.Status == Entity.RoomStatus.维修房 || selectedRoomInfo.Status == Entity.RoomStatus.锁房 || selectedRoomInfo.Status == Entity.RoomStatus.强制锁房)
                {
                    EnableAllContextMenu(false);
                    selectedPanel.ContextMenuStrip = this.contextMenuStrip1;
                    this.menu_ChangeStatus.Visible = false;
                    this.menu_SetMaintain.Enabled = false;
                    this.SetCleanRoom.Enabled = true;
                    this.SetDirtyRoom.Enabled = true;

                    //this.menu_GroupBill.Enabled = true;
                    // this.menu_BookIn.Enabled = true;
                }
                else if (selectedRoomInfo.Status == Entity.RoomStatus.住净房 || selectedRoomInfo.Status == Entity.RoomStatus.住脏房)
                {
                    EnableAllContextMenu(true);
                    selectedPanel.ContextMenuStrip = this.contextMenuStrip1;
                    this.menu_ChangeStatus.Visible = false;
                    this.menu_SankeBill.Enabled = false;
                    this.menu_BookIn.Enabled = false;
                    this.menu_GroupBill.Enabled = false;
                   
                }


                #endregion

        
        }

        private void ShowRoomInfo()
        {

            if (selectedRoomInfo != null)
            {

               
            
            
            
            }
        
        
        }

        private void EnableAllContextMenu(bool enable)
        {
            foreach (ToolStripItem menu in this.contextMenuStrip1.Items)
            {
                menu.Enabled = enable;
            }
        }
      
        private void menu_CheckOut_Click(object sender, EventArgs e)
        {
          
            if (selectedRoomInfo != null)
            {
                if (selectedRoomInfo.Status == Entity.RoomStatus.住净房 || selectedRoomInfo.Status == Entity.RoomStatus.住脏房)
                {
                    FrmRoomCheckOut dlg = new FrmRoomCheckOut();
                    dlg.RoomInfo = selectedRoomInfo;
                    dlg.ShowDialog();
                    ReflashRoomView();
                }
              
            }
        }

        private void menu_SankeBill_Click(object sender, EventArgs e)
        {

            if (selectedRoomInfo != null)
            {
                if (selectedRoomInfo.Status == Entity.RoomStatus.空净房)
                {
                    FrmEditRoomOrder dlg = new FrmEditRoomOrder();
                    dlg.RoomInfo = selectedRoomInfo;
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {

                        ReflashRoomView();

                    }
                }
                else if (selectedRoomInfo.Status == Entity.RoomStatus.预定房)
                {
                    FrmBookCondition dlg = new FrmBookCondition();
                    dlg.RoomInfo = selectedRoomInfo;
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        FrmEditRoomOrder dlgOrder = new FrmEditRoomOrder();
                        dlgOrder.RoomInfo = selectedRoomInfo;
                        if (dlg.bookInfo == null)
                        {
                            dlgOrder.ShowDialog();
                        }
                        else
                        {
                            BookInfo bookInfo = dlg.bookInfo;
                            dlgOrder.txtCompanyName.Text = bookInfo.CustomerCompany;
                            dlgOrder.txtName.Text = bookInfo.CustomerName;
                            dlgOrder.txtSource.Text = bookInfo.Source;
                            dlgOrder.txtTelephone.Text = bookInfo.CustomerTel;
                            if (dlgOrder.ShowDialog() == DialogResult.OK)
                            {
                                //删除预订
                                BLLFactory<Book>.Instance.Delete(bookInfo.ID.ToString());
                            }
                        }
                        ReflashRoomView();
                    }
                    
                }
            }


        }


        private void menu_GroupBill_Click(object sender, EventArgs e)
        {
          

         
            //if (selectedRoomInfo != null)
            //{
                FrmEditRoomGroupOrder dlg = new FrmEditRoomGroupOrder();
               // dlg.RoomInfo = selectedRoomInfo;
                if (dlg.ShowDialog() == DialogResult.OK)
                {

                    ReflashRoomView();

                }

           // }
        }

        private void menu_ModifyDeposit_Click(object sender, EventArgs e)
        {
           
            if (selectedRoomInfo != null)
            {
                FrmEditDeposit dlg = new FrmEditDeposit();
                dlg.RoomInfo = selectedRoomInfo;
                if (dlg.ShowDialog() == DialogResult.OK)
                {

                    ReflashRoomView();

                }

            }
        }

        private void menu_ModifyRegister_Click(object sender, EventArgs e)
        {
           
            if (selectedRoomInfo != null)
            {
                FrmEditRoomRegister dlg = new FrmEditRoomRegister();
                dlg.RoomInfo = selectedRoomInfo;
                dlg.ShowDialog();
               // ReflashRoomView();

            }
        }

        private void menu_SwithRoom_Click(object sender, EventArgs e)
        {
           
            if (selectedRoomInfo != null)
            {
                FrmSwitchRoom dlg = new FrmSwitchRoom();
                dlg.RoomInfo = selectedRoomInfo;
               // dlg.ShowDialog();
                if (dlg.ShowDialog() == DialogResult.OK)
                {

                    ReflashRoomView();

                }

            }
        }

        /// <summary>
        /// 消费登记
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menu_AddConsume_Click(object sender, EventArgs e)
        {

           
            if (selectedRoomInfo != null)
            {
                FrmAddConsume dlg = new FrmAddConsume();
                dlg.RoomInfo = selectedRoomInfo;
                dlg.ShowDialog();
               
            }
        }

        /// <summary>
        /// 部分结账
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menu_CheckPart_Click(object sender, EventArgs e)
        {

            if (selectedRoomInfo != null)
            {
                FrmPartCheckOut dlg = new FrmPartCheckOut();
                dlg.RoomInfo = selectedRoomInfo;
                dlg.ShowDialog();
                // BindData();
            }
        }

        private void menu_MergeBill_Click(object sender, EventArgs e)
        {

        }

        private void menu_SplitBill_Click(object sender, EventArgs e)
        {

        }

        private void menu_BookIn_Click(object sender, EventArgs e)
        {
           
            if (selectedRoomInfo != null)
            {
                FrmBookRoom dlg = new FrmBookRoom();
                dlg.RoomInfo = selectedRoomInfo;
                if (dlg.ShowDialog() == DialogResult.OK)
                {

                    ReflashRoomView();

                }

            }
        }

        private void menu_SetMaintain_Click(object sender, EventArgs e)
        {

            if (selectedRoomInfo != null)
            {

               bool result = BLLFactory<Room>.Instance.SetRoomStatus(selectedRoomInfo.RoomNo, RoomStatus.维修房.ToString());
               if (result)
               {
                 
                   ReflashRoomView();

                  
               }
              

            }

        }

        private void SetDirtyRoom_Click(object sender, EventArgs e)
        {
            if (selectedRoomInfo != null)
            {
                string roomStatus = "";
                if (selectedRoomInfo.Status == RoomStatus.空净房)
                {
                    roomStatus = RoomStatus.空脏房.ToString();
                }
                else if (selectedRoomInfo.Status == RoomStatus.住净房)
                {

                    roomStatus = RoomStatus.住脏房.ToString();
                }
                bool result = BLLFactory<Room>.Instance.SetRoomStatus(selectedRoomInfo.RoomNo, roomStatus);
                if (result)
                {
                    ReflashRoomView();


                }


            }

        }

        private void SetCleanRoom_Click(object sender, EventArgs e)
        {

            if (selectedRoomInfo != null)
            {

                string roomStatus = "";
                if (selectedRoomInfo.Status == RoomStatus.空脏房)
                {
                    roomStatus = RoomStatus.空净房.ToString();
                }
                else if (selectedRoomInfo.Status == RoomStatus.住脏房)
                {

                    roomStatus = RoomStatus.住净房.ToString();
                }
                bool result = BLLFactory<Room>.Instance.SetRoomStatus(selectedRoomInfo.RoomNo, roomStatus);
                if (result)
                {
                    ReflashRoomView();


                }


            }

        }
        private void menu_ChangeStatus_Click(object sender, EventArgs e)
        {



        }

        private void ChangeStatus()
        {

            if (selectedRoomInfo != null)
            {
                FrmChangeRoomStatus dlg = new FrmChangeRoomStatus();
                dlg.RoomInfo = selectedRoomInfo;
                dlg.ShowDialog();
               
            }
        }

        #endregion

        private void toolStripBtnReflash_Click(object sender, EventArgs e)
        {

            ReflashRoomView();

        }

        /// <summary>
        /// 刷新房态信息
        /// </summary>
        public void ReflashRoomView()
        {

            VCNum.Text = "0";
            VDNum.Text = "0";
            OCNum.Text = "0";
            ODNum.Text = "0";
            YDNum.Text = "0";
            ZDNum.Text = "0";
            YLNUM.Text = "0";
            OONum.Text = "0";

            RoomSumList.Clear();
            ReFlashRoomStatusView();
            CreateRoomSumView();
        
        }


        /// <summary>
        /// 刷新房间状态信息
        /// </summary>
        private void ReFlashRoomStatusView()
        {
            List<RoomInfo> mRoomInfo = RoomService.Instance.GetRoomStatusViewList(condition);
            if (isShowClockRoomOnly)
            {
                mRoomInfo = mRoomInfo.FindAll(delegate(RoomInfo m) { return m.IsClockRoom == true; });

            }
            foreach (Control control in roomPanel.Controls)
            {
                if (control is RoomStatusView)
                {
                    RoomStatusView mRoomStatusView = (RoomStatusView)control;
                    RoomInfo entity= mRoomInfo.FindLast(delegate(RoomInfo r) { return r.RoomNo == mRoomStatusView.RoomNum.Text.ToString().Trim(); });
                    if (entity != null)
                    {
                        //设置房态图标
                        SetRoomViewStatus(entity, mRoomStatusView);
                        //设置是否预抵和预离
                        if (entity.IsExistBook)
                        {
                            mRoomStatusView.picArrive.Visible = (entity.BookBeginTime.Date == DateTime.Now.Date ? true : false);

                        }
                        else
                        {

                            mRoomStatusView.picArrive.Visible = false;
                        
                        }

                        mRoomStatusView.pivleft.Visible = entity.IsTodayLeave;

                        //设置是否余额不足
                        if (entity.OrderInfo != null)
                        {
                            mRoomStatusView.picAlert.Visible = entity.OrderInfo.DepositMoney <= entity.ConsumedSum;
                        }
                        else
                        {
                            mRoomStatusView.picAlert.Visible = false;
                        
                        }

                    }

                     mRoomStatusView.roomPanel.Tag = entity;

                }



                //foreach (Control subControl in control.Controls)
                //{

                //    if (subControl is RoomStatusView)
                //    {

                       
                //        PictureBox findPictureBox= (PictureBox)subControl;
                //        RoomInfo entity= mRoomInfo.FindLast(delegate(RoomInfo r) { return r.RoomNo == findPictureBox.Tag.ToString(); });
                //        if(entity!=null)
                //        {
                        
                //            if (entity.IsClockRoom)
                //            {
                //                findPictureBox.Image = global::WHC.Hotel.UI.Properties.Resources.mclock;
                //            }
                //            else if (entity.OrderInfo != null && entity.OrderInfo.CreateDate.AddDays(entity.OrderInfo.PreLivedDays).ToShortDateString() == DateTime.Now.ToShortDateString())
                //            {
                //                findPictureBox.Image = global::WHC.Hotel.UI.Properties.Resources.Tip;
                //            }
                //            else
                //            {

                //                findPictureBox.Image = GetRoomImage(entity.Status);
                            
                //            }
                //            if (entity.Status == RoomStatus.空净房)
                //            {
                //                findPictureBox.Visible = false;

                //            }
                //            else
                //            {

                //                findPictureBox.Visible = true;

                            
                //            }
                //            Panel mPanel=  (Panel)findPictureBox.Parent;
                //            if(mPanel!=null)
                //            {
                //                if (entity.Status == RoomStatus.住净房 || entity.Status == RoomStatus.住脏房 || entity.IsClockRoom)
                //                {

                //                    mPanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(199)))), ((int)(((byte)(196)))), ((int)(((byte)(125)))));


                //                }
                //                else
                //                {
                //                    mPanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(255)))), ((int)(((byte)(212)))));
                                
                //                }
                //            }

                //            mPanel.Tag = entity;

                        
                //        }
                       
                        
                //    }
                
                //}

                    
           }
                
     }

        private void dgViewRoomType_CellClick(object sender, DataGridViewCellEventArgs e)
        {

            if (e.RowIndex < 0)
            {
                selectRoomType = "";

            }
            else
            {
                selectRoomType = dgViewRoomType.CurrentRow.Cells["Expand"].Value.ToString();
               
            
            }
            SearchRoomInfo();
           // e.RowIndex


        }

        private void dgViewRoomArea_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                selectRoomBuildNum = "";

            }
            else
            {
                selectRoomBuildNum = dgViewRoomArea.CurrentRow.Cells["BuildNum"].Value.ToString();


            }
            SearchRoomInfo();
        }

        private void dgViewRoomFloor_CellClick(object sender, DataGridViewCellEventArgs e)
        {

            if (e.RowIndex < 0)
            {
                selectRoomFloor = "";

            }
            else
            {
                selectRoomFloor = dgViewRoomFloor.CurrentRow.Cells["RoomFloor"].Value.ToString();


            }
            SearchRoomInfo();
        }

        private void SearchRoomInfo()
        {

            string strTemp = "";

            if (selectRoomBuildNum != "")
            {

                condition = "    BuildNum='" + selectRoomBuildNum + "'";
                strTemp = "楼栋：" + selectRoomBuildNum + "";
            }
            else
            {
                condition = "  1=1 ";
                strTemp = "楼栋：全部";
            
            }

            if (selectRoomFloor != "")
            {

                condition += "  and  Floor='" + selectRoomFloor + "'";
                strTemp += " 楼层：" + selectRoomFloor + "";
            }
            else
            {
                strTemp += " 楼层：全部";
            
            }

            if (selectRoomType != "")
            {

                condition  += "  and  RoomType='" + selectRoomType + "'";
                strTemp += " 房间类型：" + selectRoomType + "";
            }
            else
            {
                strTemp += " 房间类型：全部";
            
            }

            if (selectRoomStatus != "")
            {
                if (selectRoomStatus == "钟点房")
                {
                    isShowClockRoomOnly = true;
                }
                else
                {
                    condition += "  and  Status='" + selectRoomStatus + "'";
                    isShowClockRoomOnly = false;
                }
                strTemp += " 房间状态：" + selectRoomStatus + "";
            }
            else
            {
                strTemp += " 房间状态：全部";
                isShowClockRoomOnly = false;

            }
            lbTitle.Text = strTemp;
           // ReFlashRoomStatusView();
            CreateRoomView();
        
        
        }

        private void cboxRoomStatus_SelectedIndexChanged(object sender, EventArgs e)
        {

            if (cboxRoomStatus.Text == "全部")
            {

                selectRoomStatus = "";
            }
            else
            {

                selectRoomStatus = cboxRoomStatus.Text;
            
            
            }
            SearchRoomInfo();


        }

       

      

       

      

            
 }

        
}

        


       

      

       

